package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.border.*;

import java.awt.Font;

import javax.swing.*;

import model.*;
import control.*;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.awt.Color;

public class workOnCase extends JFrame {

	private JPanel contentPane;
	private JScrollPane scrollPane;
	private JTextField tfVlicensePlate;
	private JTextField tfVtype;
	private JTextField tfVyear;
	private JTextField tfVcolor;
	private JTextField tfVfactoryNumber;
	private JTextField tfDCcpr;
	private JTextField tfDCname;
	private JTextField tfDCaddress;
	private JTextField tfDCzipCode;
	private JTextField tfDCcity;
	private JTextField tfDCphone;
	private JTextField tfDCgsm;
	private JTextField tfDCemail;
	private JTextField tfCreated;
	private JTextField tfExtension;
	private JTextField tfContract;
	private JTextField tfDebt;
	private JTextField tfDateClosed;
	private JTextField tfCCcpr;
	private JTextField tfCCname;
	private JTextField tfCCaddress;
	private JTextField tfCCzipCode;
	private JTextField tfCCcity;
	private JTextField tfCCphone;
	private JTextField tfCCgsm;
	private JTextField tfCCemail;
	private JTextField tfDcpr;
	private JTextField tfDname;
	private JTextField tfDaddress;
	private JTextField tfDzipCode;
	private JTextField tfDcity;
	private JTextField tfDphone;
	private JTextField tfDgsm;
	private JTextField tfDemail;
	private JTextField tfCcvr;
	private JTextField tfCname;
	private JTextField tfCaddress;
	private JTextField tfCzipCode;
	private JTextField tfCcity;
	private JTextField tfCphone;
	private JTextField tfCgsm;
	private JTextField tfCemail;
	private JTextPane txtInfo;
	private JTextPane txtHistory;
	private JCheckBox boxCloseCase;
	private JCheckBox boxAssignEmp;
	private JButton btnUpdateCase;
	private PersonCtrl personCtrl = new PersonCtrl();
	private ClientCtrl clientCtrl = new ClientCtrl();
	private VehicleCtrl vehicleCtrl = new VehicleCtrl();
	private CaseCtrl caseCtrl = new CaseCtrl();
	private String id;
	private String user = "";
	private cases cases;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					workOnCase frame = new workOnCase();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public workOnCase() {
		setTitle("WORK ON CASE");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 1285, 620);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 153));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		scrollPane = new JScrollPane();
		scrollPane.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		scrollPane.setBounds(868, 45, 393, 530);
		contentPane.add(scrollPane);
		
		txtHistory = new JTextPane();
		scrollPane.setViewportView(txtHistory);
		
		JLabel lblHistory = new JLabel("HISTORY");
		lblHistory.setHorizontalAlignment(SwingConstants.CENTER);
		lblHistory.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblHistory.setBounds(868, 11, 393, 31);
		contentPane.add(lblHistory);
		
		JPanel panelVehicle = new JPanel();
		panelVehicle.setBackground(new Color(255, 255, 153));
		panelVehicle.setBounds(554, 225, 304, 174);
		contentPane.add(panelVehicle);
		panelVehicle.setLayout(null);
		panelVehicle.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "VEHICLE", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		
		JLabel label_16 = new JLabel("License Plate :");
		label_16.setHorizontalAlignment(SwingConstants.RIGHT);
		label_16.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_16.setBounds(6, 16, 114, 31);
		panelVehicle.add(label_16);
		
		tfVlicensePlate = new JTextField();
		tfVlicensePlate.setColumns(10);
		tfVlicensePlate.setBounds(126, 20, 170, 25);
		panelVehicle.add(tfVlicensePlate);
		
		JLabel label_17 = new JLabel("Type :");
		label_17.setHorizontalAlignment(SwingConstants.RIGHT);
		label_17.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_17.setBounds(6, 46, 114, 31);
		panelVehicle.add(label_17);
		
		JLabel label_18 = new JLabel("Year :");
		label_18.setHorizontalAlignment(SwingConstants.RIGHT);
		label_18.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_18.setBounds(6, 76, 114, 31);
		panelVehicle.add(label_18);
		
		tfVtype = new JTextField();
		tfVtype.setColumns(10);
		tfVtype.setBounds(126, 50, 170, 25);
		panelVehicle.add(tfVtype);
		
		tfVyear = new JTextField();
		tfVyear.setColumns(10);
		tfVyear.setBounds(126, 80, 170, 25);
		panelVehicle.add(tfVyear);
		
		JLabel label_19 = new JLabel("Color :");
		label_19.setHorizontalAlignment(SwingConstants.RIGHT);
		label_19.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_19.setBounds(6, 106, 114, 31);
		panelVehicle.add(label_19);
		
		JLabel label_20 = new JLabel("Factory Number :");
		label_20.setHorizontalAlignment(SwingConstants.RIGHT);
		label_20.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_20.setBounds(6, 136, 114, 31);
		panelVehicle.add(label_20);
		
		tfVcolor = new JTextField();
		tfVcolor.setColumns(10);
		tfVcolor.setBounds(126, 110, 170, 25);
		panelVehicle.add(tfVcolor);
		
		tfVfactoryNumber = new JTextField();
		tfVfactoryNumber.setColumns(10);
		tfVfactoryNumber.setBounds(126, 140, 170, 25);
		panelVehicle.add(tfVfactoryNumber);
		
		JPanel panelDContact = new JPanel();
		panelDContact.setBackground(new Color(255, 255, 153));
		panelDContact.setLayout(null);
		panelDContact.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "CONTACT - for debtor", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelDContact.setBounds(284, 45, 264, 264);
		contentPane.add(panelDContact);
		
		JLabel label = new JLabel("CPR :");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label.setBounds(14, 17, 64, 31);
		panelDContact.add(label);
		
		tfDCcpr = new JTextField();
		tfDCcpr.setColumns(10);
		tfDCcpr.setBounds(84, 20, 170, 25);
		panelDContact.add(tfDCcpr);
		
		JLabel label_1 = new JLabel("Name :");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_1.setBounds(17, 47, 64, 31);
		panelDContact.add(label_1);
		
		JLabel label_2 = new JLabel("Address :");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_2.setBounds(14, 77, 64, 31);
		panelDContact.add(label_2);
		
		JLabel label_3 = new JLabel("Zip Code :");
		label_3.setHorizontalAlignment(SwingConstants.RIGHT);
		label_3.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_3.setBounds(14, 107, 64, 31);
		panelDContact.add(label_3);
		
		JLabel label_4 = new JLabel("City :");
		label_4.setHorizontalAlignment(SwingConstants.RIGHT);
		label_4.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_4.setBounds(14, 137, 64, 31);
		panelDContact.add(label_4);
		
		JLabel label_5 = new JLabel("Phone :");
		label_5.setHorizontalAlignment(SwingConstants.RIGHT);
		label_5.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_5.setBounds(14, 167, 64, 31);
		panelDContact.add(label_5);
		
		JLabel label_6 = new JLabel("GSM :");
		label_6.setHorizontalAlignment(SwingConstants.RIGHT);
		label_6.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_6.setBounds(14, 197, 64, 31);
		panelDContact.add(label_6);
		
		JLabel label_7 = new JLabel("Email :");
		label_7.setHorizontalAlignment(SwingConstants.RIGHT);
		label_7.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_7.setBounds(14, 227, 64, 31);
		panelDContact.add(label_7);
		
		tfDCname = new JTextField();
		tfDCname.setColumns(10);
		tfDCname.setBounds(84, 50, 170, 25);
		panelDContact.add(tfDCname);
		
		tfDCaddress = new JTextField();
		tfDCaddress.setColumns(10);
		tfDCaddress.setBounds(84, 80, 170, 25);
		panelDContact.add(tfDCaddress);
		
		tfDCzipCode = new JTextField();
		tfDCzipCode.setColumns(10);
		tfDCzipCode.setBounds(84, 110, 170, 25);
		panelDContact.add(tfDCzipCode);
		
		tfDCcity = new JTextField();
		tfDCcity.setColumns(10);
		tfDCcity.setBounds(84, 140, 170, 25);
		panelDContact.add(tfDCcity);
		
		tfDCphone = new JTextField();
		tfDCphone.setColumns(10);
		tfDCphone.setBounds(84, 170, 170, 25);
		panelDContact.add(tfDCphone);
		
		tfDCgsm = new JTextField();
		tfDCgsm.setColumns(10);
		tfDCgsm.setBounds(84, 200, 170, 25);
		panelDContact.add(tfDCgsm);
		
		tfDCemail = new JTextField();
		tfDCemail.setColumns(10);
		tfDCemail.setBounds(84, 230, 170, 25);
		panelDContact.add(tfDCemail);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBackground(new Color(255, 255, 153));
		panel_4.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_4.setBounds(16, 11, 190, 31);
		contentPane.add(panel_4);
		panel_4.setLayout(null);
		
		JLabel lblCaseInformation = new JLabel("CASE INFORMATION");
		lblCaseInformation.setBounds(6, 5, 178, 20);
		panel_4.add(lblCaseInformation);
		lblCaseInformation.setHorizontalAlignment(SwingConstants.CENTER);
		lblCaseInformation.setFont(new Font("Times New Roman", Font.BOLD, 17));
		
		JLabel lblCreated = new JLabel("Created :");
		lblCreated.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCreated.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblCreated.setBounds(244, 16, 70, 20);
		contentPane.add(lblCreated);
		
		tfCreated = new JTextField();
		tfCreated.setEditable(false);
		tfCreated.setBounds(321, 17, 103, 20);
		contentPane.add(tfCreated);
		tfCreated.setColumns(10);
		
		JLabel lblExtension = new JLabel("Extension :");
		lblExtension.setHorizontalAlignment(SwingConstants.RIGHT);
		lblExtension.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblExtension.setBounds(437, 16, 88, 20);
		contentPane.add(lblExtension);
		
		tfExtension = new JTextField();
		tfExtension.setColumns(10);
		tfExtension.setBounds(535, 17, 103, 20);
		contentPane.add(tfExtension);
		
		JPanel panel_5 = new JPanel();
		panel_5.setBackground(new Color(255, 255, 153));
		panel_5.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "INFO", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panel_5.setBounds(554, 45, 304, 80);
		contentPane.add(panel_5);
		panel_5.setLayout(null);
		
		JLabel lblContract = new JLabel("Contract :");
		lblContract.setBounds(10, 13, 78, 31);
		panel_5.add(lblContract);
		lblContract.setHorizontalAlignment(SwingConstants.RIGHT);
		lblContract.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		
		tfContract = new JTextField();
		tfContract.setBounds(94, 16, 200, 25);
		panel_5.add(tfContract);
		tfContract.setEditable(false);
		tfContract.setColumns(10);
		
		JLabel lblDebt = new JLabel("Debt :");
		lblDebt.setBounds(10, 43, 78, 31);
		panel_5.add(lblDebt);
		lblDebt.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDebt.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		
		tfDebt = new JTextField();
		tfDebt.setBounds(94, 46, 200, 25);
		panel_5.add(tfDebt);
		tfDebt.setColumns(10);
		
		JPanel panel_6 = new JPanel();
		panel_6.setBackground(new Color(255, 255, 153));
		panel_6.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "ADDITIONAL INFO", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panel_6.setBounds(558, 125, 300, 96);
		contentPane.add(panel_6);
		panel_6.setLayout(null);
		
		txtInfo = new JTextPane();
		txtInfo.setBounds(10, 15, 280, 70);
		panel_6.add(txtInfo);
		
		boxCloseCase = new JCheckBox("CLOSE CASE");
		boxCloseCase.setBackground(new Color(255, 255, 153));
		boxCloseCase.setFont(new Font("Times New Roman", Font.BOLD, 14));
		boxCloseCase.setBounds(726, 503, 111, 23);
		contentPane.add(boxCloseCase);
		
		boxCloseCase.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean isSelected = boxCloseCase.isSelected();
				if(isSelected)
				{
					int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to close case? After update it cannot be undone.",
							"Close Case", JOptionPane.YES_NO_OPTION);
					if(reply == JOptionPane.YES_NO_OPTION)
					{
						
					}
					else
						boxCloseCase.setSelected(false);
				}
			}
		});
		
		JLabel lblDateClosed = new JLabel("Date Closed :");
		lblDateClosed.setHorizontalAlignment(SwingConstants.RIGHT);
		lblDateClosed.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblDateClosed.setBounds(627, 545, 103, 20);
		contentPane.add(lblDateClosed);
		
		tfDateClosed = new JTextField();
		tfDateClosed.setEditable(false);
		tfDateClosed.setColumns(10);
		tfDateClosed.setBounds(734, 545, 103, 20);
		contentPane.add(tfDateClosed);
		
		btnUpdateCase = new JButton("Update Case");
		btnUpdateCase.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to update the case?",
						"Update Case", JOptionPane.YES_NO_OPTION);
				if(reply == JOptionPane.YES_NO_OPTION)
				{
					//update Debtor Contact
					if (tfDCcpr.getText().equals(personCtrl.getDebtorByCpr(tfDcpr.getText()).getContact().getCpr())) 
					{
					personCtrl.updatePerson(tfDCname.getText(), tfDCaddress.getText(), tfDCzipCode.getText(), tfDCcity.getText(),
                        tfDCphone.getText(), tfDCgsm.getText(), tfDCemail.getText(), tfDCcpr.getText());
					}
					//update Client Contact
					if (tfCCcpr.getText().equals(clientCtrl.getClientByCvr(tfCcvr.getText()).getContact().getCpr())) 
					{
					personCtrl.updatePerson(tfCCname.getText(), tfCCaddress.getText(), tfCCzipCode.getText(), tfCCcity.getText(),
                        tfCCphone.getText(), tfCCgsm.getText(), tfCCemail.getText(), tfCCcpr.getText());
					}
				
					personCtrl.updateDebtor(tfDcpr.getText(), tfDname.getText(), tfDaddress.getText(), tfDzipCode.getText(), tfDcity.getText(),
                        tfDphone.getText(), tfDgsm.getText(), tfDemail.getText(), tfDCcpr.getText());
				
					clientCtrl.updateClient(tfCcvr.getText(), tfCname.getText(), tfCaddress.getText(), tfCzipCode.getText(), tfCcity.getText(),
                        tfCphone.getText(), tfCgsm.getText(), tfCemail.getText(), tfCCcpr.getText());
				
					vehicleCtrl.updateVehicle(tfVlicensePlate.getText(), tfVtype.getText(), tfVyear.getText(),
						tfVcolor.getText(), tfVfactoryNumber.getText());
					
					String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
					
					caseCtrl.updateCase(id, tfExtension.getText(), txtInfo.getText(), txtHistory.getText(), timeStamp, boxCloseCase.isSelected(), tfDebt.getText());
					
					if(boxAssignEmp.isSelected() && !personCtrl.ifAssignedToCase(user, id))
					{
						personCtrl.assignCase(user ,id);
					}
					if(boxAssignEmp.isSelected() == false && personCtrl.ifAssignedToCase(user, id))
					{
						personCtrl.unassignCase(user ,id);
					}
					JOptionPane.showMessageDialog(null,"Case has been updated.");
				}
				cases.updateCaseTable();
				
			}
		});
		btnUpdateCase.setFont(new Font("Times New Roman", Font.BOLD, 14));
		btnUpdateCase.setBounds(640, 410, 156, 49);
		contentPane.add(btnUpdateCase);
		
		JPanel panelCContact = new JPanel();
		panelCContact.setBackground(new Color(255, 255, 153));
		panelCContact.setLayout(null);
		panelCContact.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "CONTACT - for client", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelCContact.setBounds(284, 312, 264, 264);
		contentPane.add(panelCContact);
		
		JLabel label_29 = new JLabel("CPR :");
		label_29.setHorizontalAlignment(SwingConstants.RIGHT);
		label_29.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_29.setBounds(14, 17, 64, 31);
		panelCContact.add(label_29);
		
		tfCCcpr = new JTextField();
		tfCCcpr.setColumns(10);
		tfCCcpr.setBounds(84, 20, 170, 25);
		panelCContact.add(tfCCcpr);
		
		JLabel label_30 = new JLabel("Name :");
		label_30.setHorizontalAlignment(SwingConstants.RIGHT);
		label_30.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_30.setBounds(14, 47, 64, 31);
		panelCContact.add(label_30);
		
		JLabel label_31 = new JLabel("Address :");
		label_31.setHorizontalAlignment(SwingConstants.RIGHT);
		label_31.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_31.setBounds(14, 77, 64, 31);
		panelCContact.add(label_31);
		
		JLabel label_32 = new JLabel("Zip Code :");
		label_32.setHorizontalAlignment(SwingConstants.RIGHT);
		label_32.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_32.setBounds(14, 107, 64, 31);
		panelCContact.add(label_32);
		
		JLabel label_33 = new JLabel("City :");
		label_33.setHorizontalAlignment(SwingConstants.RIGHT);
		label_33.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_33.setBounds(14, 137, 64, 31);
		panelCContact.add(label_33);
		
		JLabel label_34 = new JLabel("Phone :");
		label_34.setHorizontalAlignment(SwingConstants.RIGHT);
		label_34.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_34.setBounds(14, 167, 64, 31);
		panelCContact.add(label_34);
		
		JLabel label_35 = new JLabel("GSM :");
		label_35.setHorizontalAlignment(SwingConstants.RIGHT);
		label_35.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_35.setBounds(14, 197, 64, 31);
		panelCContact.add(label_35);
		
		JLabel label_36 = new JLabel("Email :");
		label_36.setHorizontalAlignment(SwingConstants.RIGHT);
		label_36.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_36.setBounds(14, 227, 64, 31);
		panelCContact.add(label_36);
		
		tfCCname = new JTextField();
		tfCCname.setColumns(10);
		tfCCname.setBounds(84, 50, 170, 25);
		panelCContact.add(tfCCname);
		
		tfCCaddress = new JTextField();
		tfCCaddress.setColumns(10);
		tfCCaddress.setBounds(84, 80, 170, 25);
		panelCContact.add(tfCCaddress);
		
		tfCCzipCode = new JTextField();
		tfCCzipCode.setColumns(10);
		tfCCzipCode.setBounds(84, 110, 170, 25);
		panelCContact.add(tfCCzipCode);
		
		tfCCcity = new JTextField();
		tfCCcity.setColumns(10);
		tfCCcity.setBounds(84, 140, 170, 25);
		panelCContact.add(tfCCcity);
		
		tfCCphone = new JTextField();
		tfCCphone.setColumns(10);
		tfCCphone.setBounds(84, 170, 170, 25);
		panelCContact.add(tfCCphone);
		
		tfCCgsm = new JTextField();
		tfCCgsm.setColumns(10);
		tfCCgsm.setBounds(84, 200, 170, 25);
		panelCContact.add(tfCCgsm);
		
		tfCCemail = new JTextField();
		tfCCemail.setColumns(10);
		tfCCemail.setBounds(84, 230, 170, 25);
		panelCContact.add(tfCCemail);
		
		JPanel panelDebtor = new JPanel();
		panelDebtor.setBackground(new Color(255, 255, 153));
		panelDebtor.setLayout(null);
		panelDebtor.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "DEBTOR", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelDebtor.setBounds(10, 45, 264, 264);
		contentPane.add(panelDebtor);
		
		JLabel label_8 = new JLabel("CPR :");
		label_8.setHorizontalAlignment(SwingConstants.RIGHT);
		label_8.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_8.setBounds(14, 17, 64, 31);
		panelDebtor.add(label_8);
		
		tfDcpr = new JTextField();
		tfDcpr.setColumns(10);
		tfDcpr.setBounds(84, 20, 170, 25);
		panelDebtor.add(tfDcpr);
		
		JLabel label_9 = new JLabel("Name :");
		label_9.setHorizontalAlignment(SwingConstants.RIGHT);
		label_9.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_9.setBounds(14, 47, 64, 31);
		panelDebtor.add(label_9);
		
		JLabel label_10 = new JLabel("Address :");
		label_10.setHorizontalAlignment(SwingConstants.RIGHT);
		label_10.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_10.setBounds(14, 77, 64, 31);
		panelDebtor.add(label_10);
		
		JLabel label_11 = new JLabel("Zip Code :");
		label_11.setHorizontalAlignment(SwingConstants.RIGHT);
		label_11.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_11.setBounds(14, 107, 64, 31);
		panelDebtor.add(label_11);
		
		JLabel label_12 = new JLabel("City :");
		label_12.setHorizontalAlignment(SwingConstants.RIGHT);
		label_12.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_12.setBounds(14, 137, 64, 31);
		panelDebtor.add(label_12);
		
		JLabel label_13 = new JLabel("Phone :");
		label_13.setHorizontalAlignment(SwingConstants.RIGHT);
		label_13.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_13.setBounds(14, 167, 64, 31);
		panelDebtor.add(label_13);
		
		JLabel label_14 = new JLabel("GSM :");
		label_14.setHorizontalAlignment(SwingConstants.RIGHT);
		label_14.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_14.setBounds(14, 197, 64, 31);
		panelDebtor.add(label_14);
		
		JLabel label_15 = new JLabel("Email :");
		label_15.setHorizontalAlignment(SwingConstants.RIGHT);
		label_15.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_15.setBounds(14, 227, 64, 31);
		panelDebtor.add(label_15);
		
		tfDname = new JTextField();
		tfDname.setColumns(10);
		tfDname.setBounds(84, 50, 170, 25);
		panelDebtor.add(tfDname);
		
		tfDaddress = new JTextField();
		tfDaddress.setColumns(10);
		tfDaddress.setBounds(84, 80, 170, 25);
		panelDebtor.add(tfDaddress);
		
		tfDzipCode = new JTextField();
		tfDzipCode.setColumns(10);
		tfDzipCode.setBounds(84, 110, 170, 25);
		panelDebtor.add(tfDzipCode);
		
		tfDcity = new JTextField();
		tfDcity.setColumns(10);
		tfDcity.setBounds(84, 140, 170, 25);
		panelDebtor.add(tfDcity);
		
		tfDphone = new JTextField();
		tfDphone.setColumns(10);
		tfDphone.setBounds(84, 170, 170, 25);
		panelDebtor.add(tfDphone);
		
		tfDgsm = new JTextField();
		tfDgsm.setColumns(10);
		tfDgsm.setBounds(84, 200, 170, 25);
		panelDebtor.add(tfDgsm);
		
		tfDemail = new JTextField();
		tfDemail.setColumns(10);
		tfDemail.setBounds(84, 230, 170, 25);
		panelDebtor.add(tfDemail);
		
		JPanel panelClient = new JPanel();
		panelClient.setBackground(new Color(255, 255, 153));
		panelClient.setLayout(null);
		panelClient.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "CLIENT", TitledBorder.CENTER, TitledBorder.TOP, null, null));
		panelClient.setBounds(10, 312, 264, 264);
		contentPane.add(panelClient);
		
		JLabel lblCvr = new JLabel("CVR :");
		lblCvr.setHorizontalAlignment(SwingConstants.RIGHT);
		lblCvr.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		lblCvr.setBounds(14, 17, 64, 31);
		panelClient.add(lblCvr);
		
		tfCcvr = new JTextField();
		tfCcvr.setColumns(10);
		tfCcvr.setBounds(84, 20, 170, 25);
		panelClient.add(tfCcvr);
		
		JLabel label_22 = new JLabel("Name :");
		label_22.setHorizontalAlignment(SwingConstants.RIGHT);
		label_22.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_22.setBounds(14, 47, 64, 31);
		panelClient.add(label_22);
		
		JLabel label_23 = new JLabel("Address :");
		label_23.setHorizontalAlignment(SwingConstants.RIGHT);
		label_23.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_23.setBounds(14, 77, 64, 31);
		panelClient.add(label_23);
		
		JLabel label_24 = new JLabel("Zip Code :");
		label_24.setHorizontalAlignment(SwingConstants.RIGHT);
		label_24.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_24.setBounds(14, 107, 64, 31);
		panelClient.add(label_24);
		
		JLabel label_25 = new JLabel("City :");
		label_25.setHorizontalAlignment(SwingConstants.RIGHT);
		label_25.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_25.setBounds(14, 137, 64, 31);
		panelClient.add(label_25);
		
		JLabel label_26 = new JLabel("Phone :");
		label_26.setHorizontalAlignment(SwingConstants.RIGHT);
		label_26.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_26.setBounds(14, 167, 64, 31);
		panelClient.add(label_26);
		
		JLabel label_27 = new JLabel("GSM :");
		label_27.setHorizontalAlignment(SwingConstants.RIGHT);
		label_27.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_27.setBounds(14, 197, 64, 31);
		panelClient.add(label_27);
		
		JLabel label_28 = new JLabel("Email :");
		label_28.setHorizontalAlignment(SwingConstants.RIGHT);
		label_28.setFont(new Font("Times New Roman", Font.PLAIN, 12));
		label_28.setBounds(14, 227, 64, 31);
		panelClient.add(label_28);
		
		tfCname = new JTextField();
		tfCname.setColumns(10);
		tfCname.setBounds(84, 50, 170, 25);
		panelClient.add(tfCname);
		
		tfCaddress = new JTextField();
		tfCaddress.setColumns(10);
		tfCaddress.setBounds(84, 80, 170, 25);
		panelClient.add(tfCaddress);
		
		tfCzipCode = new JTextField();
		tfCzipCode.setColumns(10);
		tfCzipCode.setBounds(84, 110, 170, 25);
		panelClient.add(tfCzipCode);
		
		tfCcity = new JTextField();
		tfCcity.setColumns(10);
		tfCcity.setBounds(84, 140, 170, 25);
		panelClient.add(tfCcity);
		
		tfCphone = new JTextField();
		tfCphone.setColumns(10);
		tfCphone.setBounds(84, 170, 170, 25);
		panelClient.add(tfCphone);
		
		tfCgsm = new JTextField();
		tfCgsm.setColumns(10);
		tfCgsm.setBounds(84, 200, 170, 25);
		panelClient.add(tfCgsm);
		
		tfCemail = new JTextField();
		tfCemail.setColumns(10);
		tfCemail.setBounds(84, 230, 170, 25);
		panelClient.add(tfCemail);
		
		boxAssignEmp = new JCheckBox("Assign to Case");
		boxAssignEmp.setBackground(new Color(255, 255, 153));
		boxAssignEmp.setFont(new Font("Times New Roman", Font.BOLD, 14));
		boxAssignEmp.setBounds(638, 465, 180, 23);
		contentPane.add(boxAssignEmp);
		
		boxAssignEmp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean isSelected = boxAssignEmp.isSelected();
				if(isSelected)
				{
					int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to assign yourself to this case?",
							"Assign to Case", JOptionPane.YES_NO_OPTION);
					if(reply == JOptionPane.YES_NO_OPTION)
					{
						
					}
					else
						boxAssignEmp.setSelected(false);
					return;
				}
				else
				{
					int reply = JOptionPane.showConfirmDialog(null, "Are you sure you want to unassign yourself from this case?",
							"Assign to Case", JOptionPane.YES_NO_OPTION);
					if(reply == JOptionPane.YES_NO_OPTION)
					{
						
					}
					else
						boxAssignEmp.setSelected(true);
					return;
				}
			}
		});
	}
	
	public void setTextFields(Case _case)
	{
		setDebtorFields(_case.getDebtor());
		setDebtorContactFields(_case.getDebtor().getContact());
		setClientFields(_case.getClient());
		setClientContactFields(_case.getClient().getContact());
		setVehicleFields(_case.getVehicle());
		id = _case.getId();
		setCaseFields(_case);
	}
	
	public void setDebtorFields(Debtor debtor)
	{
		tfDcpr.setText(debtor.getCpr());
        tfDname.setText(debtor.getName());
        tfDaddress.setText(debtor.getAddress());
        tfDzipCode.setText(debtor.getZipCode());
        tfDcity.setText(debtor.getCity());
        tfDphone.setText(debtor.getPhone());
        tfDgsm.setText(debtor.getGsm());
        tfDemail.setText(debtor.getEmail());
	}
	
	public void setDebtorContactFields(Contact contact)
	{
		 tfDCcpr.setText(contact.getCpr());
         tfDCname.setText(contact.getName());
         tfDCaddress.setText(contact.getAddress());
         tfDCzipCode.setText(contact.getZipCode());
         tfDCcity.setText(contact.getCity());
         tfDCphone.setText(contact.getPhone());
         tfDCgsm.setText(contact.getGsm());
         tfDCemail.setText(contact.getEmail());
	}
	
	public void setClientFields(Client client)
	{
		 tfCcvr.setText(client.getCvr());
         tfCname.setText(client.getName());
         tfCaddress.setText(client.getAddress());
         tfCzipCode.setText(client.getZipCode());
         tfCcity.setText(client.getCity());
         tfCphone.setText(client.getPhone());
         tfCgsm.setText(client.getGsm());
         tfCemail.setText(client.getEmail());
	}
	
	public void setClientContactFields(Contact contact)
	{
		 tfCCcpr.setText(contact.getCpr());
         tfCCname.setText(contact.getName());
         tfCCaddress.setText(contact.getAddress());
         tfCCzipCode.setText(contact.getZipCode());
         tfCCcity.setText(contact.getCity());
         tfCCphone.setText(contact.getPhone());
         tfCCgsm.setText(contact.getGsm());
         tfCCemail.setText(contact.getEmail());
	}
	
	public void setVehicleFields(Vehicle veh)
	{
		tfVlicensePlate.setText(veh.getLicensePlate());
        tfVtype.setText(veh.getType());
        tfVyear.setText(veh.getYear());
        tfVcolor.setText(veh.getColor());
        tfVfactoryNumber.setText(veh.getFactoryNr());
	}
	
	public void setCaseFields(Case _case)
	{
		tfCreated.setText(_case.getStartDate());
		tfContract.setText(_case.getContract());
		
		if(!_case.getExtensionDate().equals("null"))
			tfExtension.setText(_case.getExtensionDate());
		else tfExtension.setText("");
		
		if(!_case.getDebt().equals("null"))
			tfDebt.setText(_case.getDebt());
		else tfDebt.setText("");
		
		if(!_case.getEndDate().equals("null"))
			tfDateClosed.setText(_case.getEndDate());
		else tfDateClosed.setText("");
		
		if(!_case.getInformation().equals("null"))
			txtInfo.setText(_case.getInformation());
		else txtInfo.setText("");
		
		if(!_case.getHistoryArea().equals("null"))
			txtHistory.setText(_case.getHistoryArea());
		else txtHistory.setText("");
		
		if(_case.getProcessed().equals("Closed"))
		{
			boxCloseCase.setSelected(true);
			boxCloseCase.setEnabled(false);
			btnUpdateCase.setEnabled(false);
		}
		else
		{
			boxCloseCase.setSelected(false);
			boxCloseCase.setEnabled(true);
			btnUpdateCase.setEnabled(true);
			
		}
		if(personCtrl.ifAssignedToCase(user, id))
		{
			boxAssignEmp.setSelected(true);
		}
		else
		{
			boxAssignEmp.setSelected(false);
		}
	}
	
	public void setUser(String _user)
	{
		user = _user;
	}
	
	public void setCase(cases _cases)
	{
		cases = _cases;
	}
}
